<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Apply extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/arch
	 *	- or -  
	 * 		http://example.com/index.php/arch/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/arch/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		echo $_POST['username'];
	}

	public function commit()
	{
		$this->load->helper('string');
		$serviceName = $_POST['serviceName'];
		$pv = $_POST['pv'];
		$this->load->model('commit');
		$productName = $_POST['productName'];
		$mailList = reduce_multiples($_POST['mailList'],";",TRUE);
		$expectedTime = $_POST['expectedTime'];
		$serviceName = $_POST['serviceName'];
		$submitter = $_COOKIE['username'];
		$remark = $_POST['remark'];
		$dataAmount = $_POST['dataAmount'];
		$serviceLevel = $_POST['serviceLevel'];
		$submitter = $_COOKIE['username'];
		$this->commit->insertRecord($serviceName,$mailList,$pv,$expectedTime,$submitter,'no',$dataAmount,$serviceLevel,$productName);	
		//$this->info($serviceName,$mailList,$pv,$expectedTime,$submitter,$dataAmount,$serviceLevel);	
	}


	//send mail to op
	public function info($serviceName,$mailList,$pv,$expectedTime,$submitter,$dataAmount,$serviceLevel)
	{
		$this->load->library('email');
		$this->email->from('Arch','Arch之窗');
		$mails = explode(";",$mailList);
		for($i=0;$i<count($mails);$i++) {
			$mails[$i] = trim($mails[$i]);
		}
		$this->email->to($mails);

		$this->email->subject('Arch服务申请');
		#exec("hostname",$hostname);
		$this->email->message('服务名:'.$serviceName.'<br/>'.'预期一年之后PV:'.$pv.' w'.'<br/>'.'一年之后数据量:'.$dataAmount.' G' .'<br/>'.'服务级别:'.$serviceLevel.'级'.'<br/>'.'提交者:'.$submitter.'<br/>'.'期望完成时间:'. $expectedTime.'<br/>');
		$this->email->send();
	}
}

/* End of file arch.php */
/* Location: ./application/controllers/arch.php */
